package swind.web.service.imp;

import java.text.SimpleDateFormat;

import org.springframework.stereotype.Service;

import swind.web.entities.ExamRole;
import swind.web.entities.ExamScore;
import swind.web.entities.ExamSubject;
import swind.web.entities.ExamUser;
import swind.web.service.IVoMachine;
import swind.web.vo.LoginUserVo;
import swind.web.vo.RoleVo;
import swind.web.vo.ScoreVo;
import swind.web.vo.SubjectVo;

@Service("voMachine")
public class VoMachine implements IVoMachine{
	
	
	/**
	 * 用户
	 */
	@Override
	public ExamUser VoToEntity(LoginUserVo loginVo){
		ExamUser eu=new ExamUser();
		eu.setUserId(loginVo.getUserId());
		eu.setUserName(loginVo.getUserName());
		eu.setPassword(loginVo.getPassword());
		return eu;
	}
	
	@Override
	public LoginUserVo EntityToVo(ExamUser eu){
		LoginUserVo luv=new LoginUserVo();
		luv.setUserId(eu.getUserId());
		luv.setUserName(eu.getUserName());
		luv.setPassword(eu.getPassword());
		return luv;
	}
	
	
	/**
	 * 角色
	 */
	@Override
	public RoleVo EntityToVo(ExamRole er){
		RoleVo rv=new RoleVo();
		rv.setRoleId(er.getRoleId());
		rv.setRoleName(er.getName());
		return rv;
	}
	
	@Override
	public ExamRole VoToEntity(RoleVo rv){
		ExamRole er=new ExamRole();
		er.setRoleId(rv.getRoleId());
		er.setName(rv.getRoleName());
		return er;
	}
	
	/* (non-Javadoc)
	 * @see swind.web.service.IVoMachine#EntityToVo(swind.web.entities.ExamSubject, swind.web.entities.ExamScore)
	 */
	@Override
	public SubjectVo EntityToVo(ExamSubject es,ExamScore esc){
		SubjectVo sv=new SubjectVo();
		sv.setSubId(es.getSubId());
		sv.setName(es.getName());
		sv.setDescription(es.getDescription());
		sv.setTestCount(es.getTestCount());
		sv.setTotalTime(es.getTotalTime());
		sv.setTotalScore(es.getTotalScore());
		sv.setStatus(es.isStatus());
		
		if(esc!=null){
			/*ScoreVo scv=new ScoreVo();
			scv.setId(esc.getId());
			scv.setUserId(esc.getUserId());
			scv.setSubjectId(esc.getSubjectId());
			scv.setScore(esc.getScore());
			
			SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");
			scv.setExamTime(sf.format(esc.getExamTime()));
			
			sv.setScoreVo(scv);*/
			
			sv.setScoreVo(this.EntityToVo(esc));
		}
		return sv;
	}
	
	/*@Override
	public ExamSubject VoToEntity(SubjectExamVo sv){
		ExamSubject es=new ExamSubject();
		es.setSubId(sv.getSubId());
		es.setName(sv.getSubName());
		es.setDescription(sv.getSubDescription());
		es.setTestCount(sv.getSubTestCount());
		es.setTotalTime(sv.getSubTotalTime());
		es.setTotalScore(sv.getSubTotalScore());
		es.setStatus(sv.isSubStatus());
		return es;
	}*/
	
	
	@Override
	public ScoreVo EntityToVo(ExamScore esc){
		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");
		return new ScoreVo(esc.getId(), esc.getUserId(), esc.getSubjectId(), sf.format(esc.getExamTime()), esc.getScore());
	}
}
